package test.instance {
	import flash.display.Sprite;
	
	import org.kisekiproject.evaluator.VariableStore;
	import org.kisekiproject.instance.DefinitionLibrary;
	import org.kisekiproject.instance.Instance;
	import org.kisekiproject.instance.InstanceDefinition;
	import org.kisekiproject.instance.InstanceFactory;
	import org.kisekiproject.resources.ResourceLoader;
	import test.instance.classes.TestClass;
	import test.instance.classes.TestProperty;

	/**
	 * @author mikael
	 */
	public class InstanceFactoryTest extends Sprite {
		public function InstanceFactoryTest() {

			var definitions:DefinitionLibrary=new DefinitionLibrary();
			definitions.addDefinition(new InstanceDefinition(TestClass));
			definitions.addDefinition(new InstanceDefinition(TestProperty));

			var resources:ResourceLoader=new ResourceLoader();
			var variables:VariableStore=new VariableStore();
			variables.setVariable("a", 5);

			var f:InstanceFactory=new InstanceFactory();
			f.definitions = definitions;
			f.resources = resources;
			f.variables = variables;

			var x:XML=
				<TestClass number="15">
					<text><![CDATA[{a}]]></text>
					<testProperty>
						<TestProperty>
							<prop1>hello</prop1>
							<prop2>world</prop2>
						</TestProperty>
					</testProperty>
					<arr>
						<TestProperty>
							<prop1>hello</prop1>
							<prop2>item1</prop2>
						</TestProperty>
						<TestProperty>
							<prop1>hello</prop1>
							<prop2>item2</prop2>
						</TestProperty>
					</arr>
				</TestClass>;

			var i:Instance=f.createInstanceFromXML(x);
			trace("arr: "+i.object.arr);
			variables.setVariable("a", 10);
		}
	}
}
